<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class template eof_iterator</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../program_options/reference.html#header.boost.program_options.eof_iterator_hpp" title="Header &lt;boost/program_options/eof_iterator.hpp&gt;">
<link rel="prev" href="environment_iterator.html" title="Class environment_iterator">
<link rel="next" href="program_options/ambiguous_option.html" title="Class ambiguous_option">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="environment_iterator.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../program_options/reference.html#header.boost.program_options.eof_iterator_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="program_options/ambiguous_option.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.eof_iterator"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template eof_iterator</span></h2>
<p>boost::eof_iterator</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../program_options/reference.html#header.boost.program_options.eof_iterator_hpp" title="Header &lt;boost/program_options/eof_iterator.hpp&gt;">boost/program_options/eof_iterator.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Derived<span class="special">,</span> <span class="keyword">typename</span> ValueType<span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a> <span class="special">:</span>
  <span class="keyword">public</span> <span class="identifier">iterator_facade</span><span class="special">&lt;</span> <span class="identifier">Derived</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">ValueType</span><span class="special">,</span> <span class="identifier">forward_traversal_tag</span> <span class="special">&gt;</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// <a class="link" href="eof_iterator.html#boost.eof_iteratorconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_5-bb"><span class="identifier">eof_iterator</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_6-bb">protected member functions</a></span>
  <span class="identifier">ValueType</span> <span class="special">&amp;</span> <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_6_1-bb"><span class="identifier">value</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_6_2-bb"><span class="identifier">found_eof</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_7-bb">private member functions</a></span>
  <span class="keyword">void</span> <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_7_1-bb"><span class="identifier">increment</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_7_2-bb"><span class="identifier">equal</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">const</span> <span class="identifier">ValueType</span> <span class="special">&amp;</span> <a class="link" href="eof_iterator.html#id-1_3_30_9_4_1_1_7_3-bb"><span class="identifier">dereference</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.30.9.5.3.4"></a><h2>Description</h2>
<p>The '<a class="link" href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a>' class is useful for constructing forward iterators in cases where iterator extract data from some source and it's easy to detect 'eof' -- i.e. the situation where there's no data. One apparent example is reading lines from a file.</p>
<p>Implementing such iterators using 'iterator_facade' directly would require to create class with three core operation, a couple of constructors. When using '<a class="link" href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a>', the derived class should define only one method to get new value, plus a couple of constructors.</p>
<p>The basic idea is that iterator has 'eof' bit. Two iterators are equal only if both have their 'eof' bits set. The 'get' method either obtains the new value or sets the 'eof' bit.</p>
<p>Specifically, derived class should define:</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><p>A default constructor, which creates iterator with 'eof' bit set. The constructor body should call 'found_eof' method defined here.</p></li>
<li class="listitem"><p>Some other constructor. It should initialize some 'data pointer' used in iterator operation and then call 'get'.</p></li>
<li class="listitem">
<p>The 'get' method. It should operate this way:</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>look at some 'data pointer' to see if new element is available; if not, it should call 'found_eof'.</p></li>
<li class="listitem"><p>extract new element and store it at location returned by the 'value' method.</p></li>
<li class="listitem"><p>advance the data pointer.</p></li>
</ul></div>
<p>
</p>
</li>
</ol></div>
<p>
</p>
<p>Essentially, the 'get' method has the functionality of both 'increment' and 'dereference'. It's very good for the cases where data extraction implicitly moves data pointer, like for stream operation. </p>
<div class="refsect2">
<a name="id-1.3.30.9.5.3.4.8"></a><h3>
<a name="boost.eof_iteratorconstruct-copy-destruct"></a><code class="computeroutput">eof_iterator</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><pre class="literallayout"><a name="id-1_3_30_9_4_1_1_5-bb"></a><span class="identifier">eof_iterator</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre></li></ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.30.9.5.3.4.9"></a><h3>
<a name="id-1_3_30_9_4_1_1_6-bb"></a><code class="computeroutput">eof_iterator</code> protected member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="identifier">ValueType</span> <span class="special">&amp;</span> <a name="id-1_3_30_9_4_1_1_6_1-bb"></a><span class="identifier">value</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Returns the reference which should be used by derived class to store the next value. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="id-1_3_30_9_4_1_1_6_2-bb"></a><span class="identifier">found_eof</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Should be called by derived class to indicate that it can't produce next element. </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.30.9.5.3.4.10"></a><h3>
<a name="id-1_3_30_9_4_1_1_7-bb"></a><code class="computeroutput">eof_iterator</code> private member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem"><pre class="literallayout"><span class="keyword">void</span> <a name="id-1_3_30_9_4_1_1_7_1-bb"></a><span class="identifier">increment</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">bool</span> <a name="id-1_3_30_9_4_1_1_7_2-bb"></a><span class="identifier">equal</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="eof_iterator.html" title="Class template eof_iterator">eof_iterator</a> <span class="special">&amp;</span> other<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
<li class="listitem"><pre class="literallayout"><span class="keyword">const</span> <span class="identifier">ValueType</span> <span class="special">&amp;</span> <a name="id-1_3_30_9_4_1_1_7_3-bb"></a><span class="identifier">dereference</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre></li>
</ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2002-2004 Vladimir Prus<p>Distributed under the Boost Software License, Version 1.0.
      (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
      <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="environment_iterator.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../program_options/reference.html#header.boost.program_options.eof_iterator_hpp"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="program_options/ambiguous_option.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
